package com.itbour.service.yjx.tmpl.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.dao.yjx.tmpl.YjxTmplTypeDao;
import com.itbour.dto.yjx.tmpl.YjxShowType;
import com.itbour.dto.yjx.tmpl.YjxShowTypeRDto;
import com.itbour.dto.yjx.tmpl.YjxTmplSetInfoDto;
import com.itbour.service.yjx.tmpl.YjxTmplTypeService;

/* * 	一键秀 模板组类型管理
 */
public class YjxTmplTypeServiceImpl implements YjxTmplTypeService {
	
	private YjxTmplTypeDao yjxTmplTypeDao;
	
	public Page pageTmplTypeInfo(Map<String, Object> param, Integer pageNo,
			Integer pageSize) {
		try {
			Page result = null;
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = yjxTmplTypeDao.getYjxTmplTypeCnt(param);//获取个数
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			// 分页检索
			param.put("pageSize", pageSize);
			param.put("skipResults", skipResults);
			List<YjxShowType> data = yjxTmplTypeDao.getYjxTmplTypeInfo(param);
			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
			//clearSelectDataSource(dataSource);
		}
	}
	
	// 新建一键秀 分类
	public void addTmplType(YjxShowType showType) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("title", showType.getTitle());
		param.put("desc", showType.getDesc());
		param.put("ver", showType.getVer());
		param.put("update_by", showType.getUpdate_by());
		yjxTmplTypeDao.addTmplTypeInfo(param); // 新建一键秀 分类
	}
	
	//修改分类
	public void upTmplType(YjxShowType showType) {
		Map<String, Object> param =new HashMap<String, Object>();
		if (showType.getSt_id()!=null){
			param.put("st_id",showType.getSt_id());
			if(showType.getTitle() != null) {
				param.put("title", showType.getTitle());
			}
			if(showType.getVer() != null) {
				param.put("ver", showType.getVer());
			}
			if(showType.getDesc() != null) {
				param.put("desc", showType.getDesc());
			}
			if(showType.getOrder()!= null) {
				param.put("order", showType.getOrder());
			}
			if(showType.getPublish() != null) {
				param.put("publish", showType.getPublish());
			}
			yjxTmplTypeDao.upTmplTypeById(param);
		}
	}
	
	public void upTmplType(Map<String, Object> parm){
		yjxTmplTypeDao.upTmplTypeById(parm);
	}

	// 获取 单个分类信息
	public List<YjxShowType> searchOneTmplType(Map<String, Object> parm) {
		return yjxTmplTypeDao.getYjxTmplTypeInfo(parm);
	}
	
	
	/*   * 获取 分类下的模板组
	 */
	public Page getTmplTypeRTmplSet(Map<String,Object> param, Integer pageNo, Integer pageSize) {
		try {
			Page result = null;
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = yjxTmplTypeDao.getTmplTypeRTmplSetCnt(param);
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			param.put("pageSize", pageSize);
			param.put("skipResults", skipResults);
			List<YjxShowTypeRDto> data = yjxTmplTypeDao.getTmplTypeRTmplSet(param);
			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
		}
	}
	
	public Page pageTmplSetInfo(Map<String, Object> param, Integer pageNo,
			Integer pageSize) {
		try {
			Page result = null;
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = yjxTmplTypeDao.getYjxTmplSetCnt(param);//获取个数
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			// 分页检索
			param.put("pageSize", pageSize);
			param.put("skipResults", skipResults);
			List<YjxTmplSetInfoDto> data = yjxTmplTypeDao.getYjxTmplSetInfo(param);
			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
			//clearSelectDataSource(dataSource);
		}
	}
	
	//添加适合的设计模板到专题下
	public boolean addSuitTmplSet(Map<String, Object> parm){
		try{
			yjxTmplTypeDao.addSuitTmplSet(parm);
			return true;
		}catch(Exception e){
			return false;
		}
	}
	
	public boolean delTmplTypeTS(Map<String, Object> parm){
		try{
			yjxTmplTypeDao.delTmplTypeTS(parm);
			return true;
		}catch(Exception e){
			return false;
		}
	}
	
	public boolean delTmplType(Map<String, Object> parm) {
		try {
			yjxTmplTypeDao.delTmplType(parm);
			yjxTmplTypeDao.delTmplTypeTS(parm);// 删除模板组 关联信息
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	public YjxTmplTypeDao getYjxTmplTypeDao() {
		return yjxTmplTypeDao;
	}

	public void setYjxTmplTypeDao(YjxTmplTypeDao yjxTmplTypeDao) {
		this.yjxTmplTypeDao = yjxTmplTypeDao;
	}
}
